<div class="Head"><h2>article categories</h2></div>
<div class="Middle">
    <ul class="tree treeview-red">
<?php
$numCategoriesInAColumn = ceil(count($categories)/3);
$categories_in = $categories;
$tmp = 1;

foreach($categories as $i => $category)
{
   if($i==$numCategoriesInAColumn*$tmp)
   {
       echo '</ul><ul class="tree treeview-red">';
       $tmp++;
   }
    
    echo '<li>'.$category[0]->getTitle();

//    if(count($category[1])>0)
//    {
        echo '<ul>';
        echo '<li><a href="'.str_replace("%2F","/", url_for('subcategory', $category[0])).'">'.$category[0]->getTitle().'</a></li>';
        foreach($category[1] as $subcategory)
        {
            echo '<li><a href="'.str_replace("%2F","/", url_for('subcategory', $subcategory)).'">'.$subcategory->getTitle().'</a></li>';
        }
        echo '</ul>';
//    }
    echo '</li>';
}

?>
</ul>
</div>
<div class="Bottom"><b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b></b></div>